﻿package com.gengine.utils
{
    import com.gengine.keyBoard.*;
    import com.gengine.manager.*;
    import com.mui.controls.*;
    import flash.display.*;
    import flash.events.*;
    import flash.utils.*;

    public class TimerTest extends Sprite
    {
        private var _sTime:Number;
        private var _dsTime:Number;
        private var _frame:int = 12;
        private var MaxDelay:Number = 10000;
        private var _stage:Stage;
        private var _num:int = 0;
        private var _isAlert:Boolean = false;
        private var i:int = 1;
        public static var Delay:Number = 20;
        public static var tipText:String = "检测到当前使用加速器，\n请刷新后再进行游戏";

        public function TimerTest(param1:Stage) : void
        {
            this._frame = param1.frameRate;
            this._stage = param1;
            return;
        }// end function

        public function start() : void
        {
            this._sTime = getTimer();
            this._dsTime = new Date().time;
            this._stage.addEventListener(Event.ENTER_FRAME, this.onEventFrameHandler);
            return;
        }// end function

        private function onEventFrameHandler(event:Event) : void
        {
            var _loc_2:String = this;
            var _loc_3:* = this.i + 1;
            _loc_2.i = _loc_3;
            if (this.i % 5 == 0)
            {
                this.testChangeTime();
                if (this.i > 300)
                {
                    this.i = 1;
                    this._num = 0;
                }
            }
            return;
        }// end function

        private function testChangeTime() : void
        {
            var _loc_1:* = getTimer();
            var _loc_2:* = new Date().time;
            var _loc_3:* = _loc_1 - this._sTime;
            var _loc_4:* = _loc_2 - this._dsTime;
            var _loc_5:* = Math.abs(_loc_3 - _loc_4);
            if (_loc_5 > Delay && _loc_5 < this.MaxDelay)
            {
                var _loc_6:String = this;
                var _loc_7:* = this._num + 1;
                _loc_6._num = _loc_7;
                if (this._num > 5)
                {
                    if (this._isAlert == false)
                    {
                        dispatchEvent(new Event(Event.CLOSE));
                        KeyBoardManager.instance.cancelListener();
                        this._isAlert = true;
                        Alert.show(tipText, null, 0, null, this.close);
                    }
                }
            }
            this._sTime = _loc_1;
            this._dsTime = _loc_2;
            return;
        }// end function

        private function close(param1:int) : void
        {
            this._isAlert = false;
            BrowerManager.instance.reload();
            this._stage.removeEventListener(Event.ENTER_FRAME, this.onEventFrameHandler);
            return;
        }// end function

    }
}
